home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_xemacs.idb / usr / freeware / lib / xemacs-20.4 / lisp / packages / makesum.el.z / makesum.el
Encoding:
Text File  |  1998-05-21  |  3.8 KB  |  121 lines

  1. ;;; makesum.el --- generate key binding summary for Emacs
  2.  
  3. ;; Copyright (C) 1985 Free Software Foundation, Inc.
  4.  
  5. ;; Maintainer: FSF
  6. ;; Keywords: help
  7.  
  8. ;; This file is part of XEmacs.
  9.  
  10. ;; XEmacs is free software; you can redistribute it and/or modify it
  11. ;; under the terms of the GNU General Public License as published by
  12. ;; the Free Software Foundation; either version 2, or (at your option)
  13. ;; any later version.
  14.  
  15. ;; XEmacs is distributed in the hope that it will be useful, but
  16. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  18. ;; General Public License for more details.
  19.  
  20. ;; You should have received a copy of the GNU General Public License
  21. ;; along with XEmacs; see the file COPYING.  If not, write to the Free
  22. ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  23. ;; 02111-1307, USA.
  24.  
  25. ;;; Synched up with: FSF 19.34.
  26.  
  27. ;;; Commentary:
  28.  
  29. ;; Displays a nice human-readable summary of all keybindings in a
  30. ;; two-column format.
  31.  
  32. ;;; Code:
  33.  
  34. ;;;###autoload
  35. (defun make-command-summary ()
  36.   "Make a summary of current key bindings in the buffer *Summary*.
  37. Previous contents of that buffer are killed first."
  38.   (interactive)
  39.   (message "Making command summary...")
  40.   ;; This puts a description of bindings in a buffer called *Help*.
  41.   (save-window-excursion
  42.    (describe-bindings))
  43.   (with-output-to-temp-buffer "*Summary*"
  44.     (save-excursion
  45.      (let ((cur-mode mode-name))
  46.        (set-buffer standard-output)
  47.        (erase-buffer)
  48.        (insert-buffer-substring "*Help*")
  49.        (goto-char (point-min))
  50.        (delete-region (point) (progn (forward-line 1) (point)))
  51.        (while (search-forward "         " nil t)
  52.      (replace-match "  "))
  53.        (goto-char (point-min))
  54.        (while (search-forward "-@ " nil t)
  55.      (replace-match "-SP"))
  56.        (goto-char (point-min))
  57.        (while (search-forward "  .. ~ " nil t)
  58.      (replace-match "SP .. ~"))
  59.        (goto-char (point-min))
  60.        (while (search-forward "C-?" nil t)
  61.      (replace-match "DEL"))
  62.        (goto-char (point-min))
  63.        (while (search-forward "C-i" nil t)
  64.      (replace-match "TAB"))
  65.        (goto-char (point-min))
  66.        (if (re-search-forward "^Local Bindings:" nil t)
  67.        (progn
  68.         (forward-char -1)
  69.         (insert " for " cur-mode " Mode")
  70.         (while (search-forward "??\n" nil t)
  71.           (delete-region (point)
  72.                  (progn
  73.                   (forward-line -1)
  74.                   (point))))))
  75.        (goto-char (point-min))
  76.        (insert
  77.     (cond ((featurep 'xemacs) "XEmacs")
  78.           ((featurep 'infodock) "InfoDock")
  79.           (t "Emacs")))
  80.        (insert " command summary, " (substring (current-time-string) 0 10)
  81.            ".\n")
  82.        ;; Delete "key    binding" and underlining of dashes.
  83.        (delete-region (point) (progn (forward-line 2) (point)))
  84.        (forward-line 1)            ;Skip blank line
  85.        (while (not (eobp))
  86.      (let ((beg (point)))
  87.        (or (re-search-forward "^$" nil t)
  88.            (goto-char (point-max)))
  89.        (double-column beg (point))
  90.        (forward-line 1)))
  91.        (goto-char (point-min)))))
  92.   (message "Making command summary...done"))
  93.  
  94. (defun double-column (start end)
  95.   (interactive "r")
  96.   (let (half line lines nlines
  97.     (from-end (- (point-max) end)))
  98.     (setq nlines (count-lines start end))
  99.     (if (<= nlines 1)
  100.     nil
  101.       (setq half (/ (1+ nlines) 2))
  102.       (goto-char start)
  103.       (save-excursion
  104.        (forward-line half)
  105.        (while (< half nlines)
  106.      (setq half (1+ half))
  107.      (setq line (buffer-substring (point) (save-excursion (end-of-line) (point))))
  108.      (setq lines (cons line lines))
  109.      (delete-region (point) (progn (forward-line 1) (point)))))
  110.       (setq lines (nreverse lines))
  111.       (while lines
  112.     (end-of-line)
  113.     ;; XEmacs change
  114.     (indent-to 41 1)
  115.     (insert (car lines))
  116.     (forward-line 1)
  117.     (setq lines (cdr lines))))
  118.     (goto-char (- (point-max) from-end))))
  119.  
  120. ;;; makesum.el ends here
  121.